package com.itzyf.pokemondata.activity.setting

import android.content.Intent
import com.itzyf.pokemondata.activity.gallery.ImageZoomActivity
import com.tydic.baselibrary.activity.BaseActivity
import com.zzhoujay.richtext.RichText
import kotlinx.android.synthetic.main.activity_markdown.*


class AboutUsActivity : BaseActivity() {
    override fun handlerActivity() {
        RichText.initCacheDir(this)
        readAbout()
    }

    private fun setContent(text: String) {
        RichText
            .fromMarkdown(text)
            .imageClick { imageUrls, position ->
                run {
                    val intent = Intent(this@AboutUsActivity, ImageZoomActivity::class.java)
                    intent.putExtra("title", "查看图片")
                    intent.putExtra("image", imageUrls[position])
                    startActivity(intent)
                }
            }
            .into(content)
    }

    override fun getContentViewId() = com.itzyf.pokemondata.R.layout.activity_markdown

    override fun getToolbarTitle() = "关于APP"

    private fun readAbout() {
        val stream = resources.assets.open("about.md")
        return stream.buffered().reader().use { reader -> setContent(reader.readText()) }
    }

}